package com.atguigu.jxc.controller;

import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.service.UnitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author dxt
 * @create 2025-07-16-15:04
 */
@RestController
@RequestMapping("/unit")
public class UnitController {

    @Autowired
    private UnitService unitService;

    /**
     * 获取所有单位
     * @return
     */
    @PostMapping("/list")
    public Map<String, Object> getUnitList() {
        return unitService.getUnitList();
    }


    /**
     * 添加单位
     * @param unitName
     * @return
     */
    @PostMapping("/save")
    public ServiceVO saveUnit(String unitName) {
        unitService.saveUnit(unitName);
        return new ServiceVO(100, "添加成功", null);
    }

    /**
     * 删除单位
     * @param unitId
     * @return
     */
    @PostMapping("/delete")
    public ServiceVO deleteUnit(Integer unitId) {
        unitService.deleteUnit(unitId);
        return new ServiceVO(100, "删除成功", null);
    }


}
